{
  "cells": [
    {
      "cell_type": "markdown",
      "source": [
        "# Logistic Regression"
      ],
      "metadata": {}
    },
    {
      "cell_type": "markdown",
      "source": [
        "Step 1: Data Pre-Processing"
      ],
      "metadata": {}
    },
    {
      "cell_type": "code",
      "source": [
        "import numpy as np\n",
        "import matplotlib.pyplot as plt\n",
        "import pandas as pd\n",
        "\n",
        "import warnings\n",
        "warnings.filterwarnings(\"ignore\")\n",
        "\n",
        "import yfinance as yf\n",
        "yf.pdr_override()"
      ],
      "outputs": [],
      "execution_count": 1,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# input\n",
        "symbol = 'AMD'\n",
        "start = '2014-01-01'\n",
        "end = '2018-08-27'\n",
        "\n",
        "# Read data \n",
        "dataset = yf.download(symbol,start,end)\n",
        "\n",
        "# Only keep close columns \n",
        "dataset.head()"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "[*********************100%***********************]  1 of 1 downloaded\n"
          ]
        },
        {
          "output_type": "execute_result",
          "execution_count": 2,
          "data": {
            "text/plain": [
              "            Open  High   Low  Close  Adj Close    Volume\n",
              "Date                                                    \n",
              "2014-01-02  3.85  3.98  3.84   3.95       3.95  20548400\n",
              "2014-01-03  3.98  4.00  3.88   4.00       4.00  22887200\n",
              "2014-01-06  4.01  4.18  3.99   4.13       4.13  42398300\n",
              "2014-01-07  4.19  4.25  4.11   4.18       4.18  42932100\n",
              "2014-01-08  4.23  4.26  4.14   4.18       4.18  30678700"
            ],
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>Open</th>\n",
              "      <th>High</th>\n",
              "      <th>Low</th>\n",
              "      <th>Close</th>\n",
              "      <th>Adj Close</th>\n",
              "      <th>Volume</th>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>Date</th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>2014-01-02</th>\n",
              "      <td>3.85</td>\n",
              "      <td>3.98</td>\n",
              "      <td>3.84</td>\n",
              "      <td>3.95</td>\n",
              "      <td>3.95</td>\n",
              "      <td>20548400</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2014-01-03</th>\n",
              "      <td>3.98</td>\n",
              "      <td>4.00</td>\n",
              "      <td>3.88</td>\n",
              "      <td>4.00</td>\n",
              "      <td>4.00</td>\n",
              "      <td>22887200</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2014-01-06</th>\n",
              "      <td>4.01</td>\n",
              "      <td>4.18</td>\n",
              "      <td>3.99</td>\n",
              "      <td>4.13</td>\n",
              "      <td>4.13</td>\n",
              "      <td>42398300</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2014-01-07</th>\n",
              "      <td>4.19</td>\n",
              "      <td>4.25</td>\n",
              "      <td>4.11</td>\n",
              "      <td>4.18</td>\n",
              "      <td>4.18</td>\n",
              "      <td>42932100</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2014-01-08</th>\n",
              "      <td>4.23</td>\n",
              "      <td>4.26</td>\n",
              "      <td>4.14</td>\n",
              "      <td>4.18</td>\n",
              "      <td>4.18</td>\n",
              "      <td>30678700</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ]
          },
          "metadata": {}
        }
      ],
      "execution_count": 2,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "dataset['Buy_Sell'] = np.where(dataset['Adj Close'].shift(-1) > dataset['Adj Close'],1,-1)"
      ],
      "outputs": [],
      "execution_count": 3,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "dataset.head()"
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "execution_count": 4,
          "data": {
            "text/plain": [
              "            Open  High   Low  Close  Adj Close    Volume  Buy_Sell\n",
              "Date                                                              \n",
              "2014-01-02  3.85  3.98  3.84   3.95       3.95  20548400         1\n",
              "2014-01-03  3.98  4.00  3.88   4.00       4.00  22887200         1\n",
              "2014-01-06  4.01  4.18  3.99   4.13       4.13  42398300         1\n",
              "2014-01-07  4.19  4.25  4.11   4.18       4.18  42932100        -1\n",
              "2014-01-08  4.23  4.26  4.14   4.18       4.18  30678700        -1"
            ],
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>Open</th>\n",
              "      <th>High</th>\n",
              "      <th>Low</th>\n",
              "      <th>Close</th>\n",
              "      <th>Adj Close</th>\n",
              "      <th>Volume</th>\n",
              "      <th>Buy_Sell</th>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>Date</th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>2014-01-02</th>\n",
              "      <td>3.85</td>\n",
              "      <td>3.98</td>\n",
              "      <td>3.84</td>\n",
              "      <td>3.95</td>\n",
              "      <td>3.95</td>\n",
              "      <td>20548400</td>\n",
              "      <td>1</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2014-01-03</th>\n",
              "      <td>3.98</td>\n",
              "      <td>4.00</td>\n",
              "      <td>3.88</td>\n",
              "      <td>4.00</td>\n",
              "      <td>4.00</td>\n",
              "      <td>22887200</td>\n",
              "      <td>1</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2014-01-06</th>\n",
              "      <td>4.01</td>\n",
              "      <td>4.18</td>\n",
              "      <td>3.99</td>\n",
              "      <td>4.13</td>\n",
              "      <td>4.13</td>\n",
              "      <td>42398300</td>\n",
              "      <td>1</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2014-01-07</th>\n",
              "      <td>4.19</td>\n",
              "      <td>4.25</td>\n",
              "      <td>4.11</td>\n",
              "      <td>4.18</td>\n",
              "      <td>4.18</td>\n",
              "      <td>42932100</td>\n",
              "      <td>-1</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2014-01-08</th>\n",
              "      <td>4.23</td>\n",
              "      <td>4.26</td>\n",
              "      <td>4.14</td>\n",
              "      <td>4.18</td>\n",
              "      <td>4.18</td>\n",
              "      <td>30678700</td>\n",
              "      <td>-1</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ]
          },
          "metadata": {}
        }
      ],
      "execution_count": 4,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "dataset['Buy_Sell'] = dataset['Buy_Sell'].astype('int')"
      ],
      "outputs": [],
      "execution_count": 5,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# Define X\n",
        "X = np.asarray(dataset[['Open', 'High', 'Low', 'Adj Close', 'Volume']])\n",
        "X[0:5]"
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "execution_count": 6,
          "data": {
            "text/plain": [
              "array([[3.85000e+00, 3.98000e+00, 3.84000e+00, 3.95000e+00, 2.05484e+07],\n",
              "       [3.98000e+00, 4.00000e+00, 3.88000e+00, 4.00000e+00, 2.28872e+07],\n",
              "       [4.01000e+00, 4.18000e+00, 3.99000e+00, 4.13000e+00, 4.23983e+07],\n",
              "       [4.19000e+00, 4.25000e+00, 4.11000e+00, 4.18000e+00, 4.29321e+07],\n",
              "       [4.23000e+00, 4.26000e+00, 4.14000e+00, 4.18000e+00, 3.06787e+07]])"
            ]
          },
          "metadata": {}
        }
      ],
      "execution_count": 6,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# Define y\n",
        "y = np.asarray(dataset['Buy_Sell'])\n",
        "y[0:5]"
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "execution_count": 7,
          "data": {
            "text/plain": [
              "array([ 1,  1,  1, -1, -1])"
            ]
          },
          "metadata": {}
        }
      ],
      "execution_count": 7,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "Step 2: Normalize Dataset"
      ],
      "metadata": {}
    },
    {
      "cell_type": "code",
      "source": [
        "from sklearn import preprocessing\n",
        "X = preprocessing.StandardScaler().fit(X).transform(X)\n",
        "X[0:5]"
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "execution_count": 8,
          "data": {
            "text/plain": [
              "array([[-0.64855413, -0.63841038, -0.63386523, -0.62754122, -0.50102319],\n",
              "       [-0.62190649, -0.63439667, -0.62549188, -0.6173066 , -0.43332499],\n",
              "       [-0.61575704, -0.59827322, -0.60246516, -0.59069658,  0.13143746],\n",
              "       [-0.57886031, -0.58422521, -0.57734511, -0.58046196,  0.14688867],\n",
              "       [-0.57066103, -0.58221835, -0.57106509, -0.58046196, -0.20779457]])"
            ]
          },
          "metadata": {}
        }
      ],
      "execution_count": 8,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# Splitting the dataset into the Training set and Test set\n",
        "from sklearn.cross_validation import train_test_split\n",
        "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.25, random_state = 0)\n",
        "print ('Train set:', X_train.shape,  y_train.shape)\n",
        "print ('Test set:', X_test.shape,  y_test.shape)"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Train set: (879, 5) (879,)\n",
            "Test set: (293, 5) (293,)\n"
          ]
        }
      ],
      "execution_count": 9,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "Step 2: Logistic Regression Model"
      ],
      "metadata": {}
    },
    {
      "cell_type": "code",
      "source": [
        "# Fitting Logistic Regression to the Training set\n",
        "from sklearn.linear_model import LogisticRegression\n",
        "from sklearn.metrics import confusion_matrix\n",
        "LR = LogisticRegression(C=0.01, solver='liblinear').fit(X_train,y_train)\n",
        "LR"
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "execution_count": 10,
          "data": {
            "text/plain": [
              "LogisticRegression(C=0.01, class_weight=None, dual=False, fit_intercept=True,\n",
              "          intercept_scaling=1, max_iter=100, multi_class='ovr', n_jobs=1,\n",
              "          penalty='l2', random_state=None, solver='liblinear', tol=0.0001,\n",
              "          verbose=0, warm_start=False)"
            ]
          },
          "metadata": {}
        }
      ],
      "execution_count": 10,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "Step 3: Prediction"
      ],
      "metadata": {}
    },
    {
      "cell_type": "code",
      "source": [
        "# Predicting the Test set results\n",
        "yhat = LR.predict(X_test)\n",
        "yhat"
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "execution_count": 11,
          "data": {
            "text/plain": [
              "array([ 1,  1, -1, -1, -1, -1,  1,  1, -1,  1, -1,  1, -1,  1, -1,  1,  1,\n",
              "       -1,  1, -1, -1, -1, -1, -1,  1, -1, -1,  1,  1, -1,  1,  1,  1, -1,\n",
              "        1,  1, -1, -1, -1,  1, -1, -1,  1,  1,  1, -1,  1, -1, -1,  1,  1,\n",
              "        1, -1,  1,  1,  1,  1,  1,  1, -1, -1, -1, -1,  1, -1, -1,  1, -1,\n",
              "       -1, -1,  1, -1,  1,  1, -1, -1,  1, -1, -1,  1, -1,  1, -1, -1,  1,\n",
              "        1,  1, -1, -1, -1, -1,  1,  1,  1,  1, -1,  1, -1, -1,  1,  1,  1,\n",
              "        1,  1,  1,  1, -1,  1,  1, -1, -1, -1, -1, -1, -1, -1, -1, -1,  1,\n",
              "        1,  1,  1,  1, -1, -1,  1,  1, -1,  1, -1, -1,  1, -1,  1,  1, -1,\n",
              "       -1,  1, -1, -1, -1, -1, -1,  1, -1, -1,  1,  1, -1,  1, -1,  1, -1,\n",
              "        1, -1,  1, -1,  1, -1,  1,  1,  1, -1,  1,  1, -1,  1,  1,  1, -1,\n",
              "        1,  1, -1, -1, -1,  1,  1, -1, -1, -1, -1, -1,  1, -1, -1,  1,  1,\n",
              "       -1, -1, -1, -1,  1, -1, -1,  1, -1, -1,  1,  1,  1,  1, -1, -1,  1,\n",
              "        1, -1, -1, -1, -1, -1, -1, -1, -1, -1,  1,  1,  1,  1, -1,  1,  1,\n",
              "        1,  1, -1,  1,  1, -1,  1,  1,  1, -1,  1, -1,  1, -1,  1,  1,  1,\n",
              "        1, -1, -1,  1,  1,  1, -1,  1, -1,  1,  1, -1,  1,  1,  1, -1,  1,\n",
              "       -1,  1,  1, -1,  1, -1, -1, -1,  1,  1,  1,  1, -1,  1, -1,  1,  1,\n",
              "       -1, -1, -1,  1,  1, -1, -1, -1, -1,  1, -1,  1,  1,  1,  1, -1, -1,\n",
              "       -1,  1,  1, -1])"
            ]
          },
          "metadata": {}
        }
      ],
      "execution_count": 11,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# predict_proba is returns of estimates for all classes, ordered by the label of classes. \n",
        "# The first column is the probability of class 1, P(Y=1|X), and second column is probability of class 0, P(Y=0|X)\n",
        "yhat_prob = LR.predict_proba(X_test)\n",
        "yhat_prob"
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "execution_count": 12,
          "data": {
            "text/plain": [
              "array([[0.45964182, 0.54035818],\n",
              "       [0.46443403, 0.53556597],\n",
              "       [0.50397715, 0.49602285],\n",
              "       [0.51185249, 0.48814751],\n",
              "       [0.51204791, 0.48795209],\n",
              "       [0.52149107, 0.47850893],\n",
              "       [0.46375946, 0.53624054],\n",
              "       [0.49262736, 0.50737264],\n",
              "       [0.50968857, 0.49031143],\n",
              "       [0.45729166, 0.54270834],\n",
              "       [0.50318484, 0.49681516],\n",
              "       [0.48929741, 0.51070259],\n",
              "       [0.50852743, 0.49147257],\n",
              "       [0.48200559, 0.51799441],\n",
              "       [0.51217314, 0.48782686],\n",
              "       [0.47065543, 0.52934457],\n",
              "       [0.45360871, 0.54639129],\n",
              "       [0.50709486, 0.49290514],\n",
              "       [0.46592349, 0.53407651],\n",
              "       [0.50685718, 0.49314282],\n",
              "       [0.50733108, 0.49266892],\n",
              "       [0.50719419, 0.49280581],\n",
              "       [0.50449033, 0.49550967],\n",
              "       [0.50648358, 0.49351642],\n",
              "       [0.46396373, 0.53603627],\n",
              "       [0.51023834, 0.48976166],\n",
              "       [0.50762412, 0.49237588],\n",
              "       [0.45945976, 0.54054024],\n",
              "       [0.47156297, 0.52843703],\n",
              "       [0.50757982, 0.49242018],\n",
              "       [0.48276295, 0.51723705],\n",
              "       [0.45391903, 0.54608097],\n",
              "       [0.47478128, 0.52521872],\n",
              "       [0.51361493, 0.48638507],\n",
              "       [0.47896304, 0.52103696],\n",
              "       [0.44704097, 0.55295903],\n",
              "       [0.50518282, 0.49481718],\n",
              "       [0.51199756, 0.48800244],\n",
              "       [0.51069043, 0.48930957],\n",
              "       [0.48849104, 0.51150896],\n",
              "       [0.51289259, 0.48710741],\n",
              "       [0.51076088, 0.48923912],\n",
              "       [0.45297835, 0.54702165],\n",
              "       [0.43224039, 0.56775961],\n",
              "       [0.49979198, 0.50020802],\n",
              "       [0.50879274, 0.49120726],\n",
              "       [0.48279092, 0.51720908],\n",
              "       [0.51286443, 0.48713557],\n",
              "       [0.5076421 , 0.4923579 ],\n",
              "       [0.47334607, 0.52665393],\n",
              "       [0.46444443, 0.53555557],\n",
              "       [0.45019155, 0.54980845],\n",
              "       [0.5072148 , 0.4927852 ],\n",
              "       [0.45121819, 0.54878181],\n",
              "       [0.46130672, 0.53869328],\n",
              "       [0.47399365, 0.52600635],\n",
              "       [0.49059563, 0.50940437],\n",
              "       [0.45603253, 0.54396747],\n",
              "       [0.47490765, 0.52509235],\n",
              "       [0.5093253 , 0.4906747 ],\n",
              "       [0.5158042 , 0.4841958 ],\n",
              "       [0.50699681, 0.49300319],\n",
              "       [0.51056662, 0.48943338],\n",
              "       [0.46834809, 0.53165191],\n",
              "       [0.5042861 , 0.4957139 ],\n",
              "       [0.50525752, 0.49474248],\n",
              "       [0.46593443, 0.53406557],\n",
              "       [0.50951489, 0.49048511],\n",
              "       [0.50694593, 0.49305407],\n",
              "       [0.51298386, 0.48701614],\n",
              "       [0.48340052, 0.51659948],\n",
              "       [0.51047983, 0.48952017],\n",
              "       [0.47007945, 0.52992055],\n",
              "       [0.47773914, 0.52226086],\n",
              "       [0.51035557, 0.48964443],\n",
              "       [0.50312533, 0.49687467],\n",
              "       [0.45183278, 0.54816722],\n",
              "       [0.51134675, 0.48865325],\n",
              "       [0.50994962, 0.49005038],\n",
              "       [0.43211243, 0.56788757],\n",
              "       [0.51166939, 0.48833061],\n",
              "       [0.48830092, 0.51169908],\n",
              "       [0.50847124, 0.49152876],\n",
              "       [0.50714746, 0.49285254],\n",
              "       [0.47063791, 0.52936209],\n",
              "       [0.45595865, 0.54404135],\n",
              "       [0.46943131, 0.53056869],\n",
              "       [0.51275401, 0.48724599],\n",
              "       [0.51472653, 0.48527347],\n",
              "       [0.50348307, 0.49651693],\n",
              "       [0.50330421, 0.49669579],\n",
              "       [0.49936735, 0.50063265],\n",
              "       [0.45359767, 0.54640233],\n",
              "       [0.45179965, 0.54820035],\n",
              "       [0.48533066, 0.51466934],\n",
              "       [0.50902166, 0.49097834],\n",
              "       [0.48735358, 0.51264642],\n",
              "       [0.51191672, 0.48808328],\n",
              "       [0.50933023, 0.49066977],\n",
              "       [0.47455448, 0.52544552],\n",
              "       [0.45818987, 0.54181013],\n",
              "       [0.45397357, 0.54602643],\n",
              "       [0.46847043, 0.53152957],\n",
              "       [0.44896726, 0.55103274],\n",
              "       [0.48844947, 0.51155053],\n",
              "       [0.45281354, 0.54718646],\n",
              "       [0.50998098, 0.49001902],\n",
              "       [0.49954537, 0.50045463],\n",
              "       [0.49867933, 0.50132067],\n",
              "       [0.50624071, 0.49375929],\n",
              "       [0.51183008, 0.48816992],\n",
              "       [0.5102517 , 0.4897483 ],\n",
              "       [0.50636219, 0.49363781],\n",
              "       [0.51048621, 0.48951379],\n",
              "       [0.51115754, 0.48884246],\n",
              "       [0.51509894, 0.48490106],\n",
              "       [0.50805799, 0.49194201],\n",
              "       [0.50972266, 0.49027734],\n",
              "       [0.450768  , 0.549232  ],\n",
              "       [0.45342222, 0.54657778],\n",
              "       [0.44188294, 0.55811706],\n",
              "       [0.48788947, 0.51211053],\n",
              "       [0.44364944, 0.55635056],\n",
              "       [0.50378036, 0.49621964],\n",
              "       [0.51435684, 0.48564316],\n",
              "       [0.4553537 , 0.5446463 ],\n",
              "       [0.48965795, 0.51034205],\n",
              "       [0.50762622, 0.49237378],\n",
              "       [0.46593521, 0.53406479],\n",
              "       [0.50717495, 0.49282505],\n",
              "       [0.51540173, 0.48459827],\n",
              "       [0.43466617, 0.56533383],\n",
              "       [0.50520118, 0.49479882],\n",
              "       [0.47605952, 0.52394048],\n",
              "       [0.46021029, 0.53978971],\n",
              "       [0.50661914, 0.49338086],\n",
              "       [0.50821354, 0.49178646],\n",
              "       [0.49565709, 0.50434291],\n",
              "       [0.50513151, 0.49486849],\n",
              "       [0.51297688, 0.48702312],\n",
              "       [0.50281617, 0.49718383],\n",
              "       [0.50355048, 0.49644952],\n",
              "       [0.51157805, 0.48842195],\n",
              "       [0.49599624, 0.50400376],\n",
              "       [0.51065444, 0.48934556],\n",
              "       [0.50874132, 0.49125868],\n",
              "       [0.46864118, 0.53135882],\n",
              "       [0.45982138, 0.54017862],\n",
              "       [0.51121693, 0.48878307],\n",
              "       [0.45169505, 0.54830495],\n",
              "       [0.50374237, 0.49625763],\n",
              "       [0.47779135, 0.52220865],\n",
              "       [0.50778262, 0.49221738],\n",
              "       [0.46300035, 0.53699965],\n",
              "       [0.51140527, 0.48859473],\n",
              "       [0.45690499, 0.54309501],\n",
              "       [0.50926193, 0.49073807],\n",
              "       [0.46452931, 0.53547069],\n",
              "       [0.51229388, 0.48770612],\n",
              "       [0.45310193, 0.54689807],\n",
              "       [0.46234826, 0.53765174],\n",
              "       [0.47204117, 0.52795883],\n",
              "       [0.5041458 , 0.4958542 ],\n",
              "       [0.45142868, 0.54857132],\n",
              "       [0.45829405, 0.54170595],\n",
              "       [0.50792885, 0.49207115],\n",
              "       [0.46894381, 0.53105619],\n",
              "       [0.46819543, 0.53180457],\n",
              "       [0.45599976, 0.54400024],\n",
              "       [0.5077568 , 0.4922432 ],\n",
              "       [0.45026653, 0.54973347],\n",
              "       [0.46600189, 0.53399811],\n",
              "       [0.50208683, 0.49791317],\n",
              "       [0.51321839, 0.48678161],\n",
              "       [0.50825988, 0.49174012],\n",
              "       [0.45762972, 0.54237028],\n",
              "       [0.46257731, 0.53742269],\n",
              "       [0.51379238, 0.48620762],\n",
              "       [0.50198839, 0.49801161],\n",
              "       [0.50978835, 0.49021165],\n",
              "       [0.51291768, 0.48708232],\n",
              "       [0.50719594, 0.49280406],\n",
              "       [0.47138677, 0.52861323],\n",
              "       [0.51231689, 0.48768311],\n",
              "       [0.51019743, 0.48980257],\n",
              "       [0.46578563, 0.53421437],\n",
              "       [0.49895118, 0.50104882],\n",
              "       [0.50605205, 0.49394795],\n",
              "       [0.50730895, 0.49269105],\n",
              "       [0.51162266, 0.48837734],\n",
              "       [0.50707627, 0.49292373],\n",
              "       [0.48433189, 0.51566811],\n",
              "       [0.51320698, 0.48679302],\n",
              "       [0.5073677 , 0.4926323 ],\n",
              "       [0.47351295, 0.52648705],\n",
              "       [0.51896908, 0.48103092],\n",
              "       [0.50268033, 0.49731967],\n",
              "       [0.42305134, 0.57694866],\n",
              "       [0.46709931, 0.53290069],\n",
              "       [0.45445567, 0.54554433],\n",
              "       [0.47948561, 0.52051439],\n",
              "       [0.50969703, 0.49030297],\n",
              "       [0.5082559 , 0.4917441 ],\n",
              "       [0.45151696, 0.54848304],\n",
              "       [0.49906979, 0.50093021],\n",
              "       [0.50786592, 0.49213408],\n",
              "       [0.50972849, 0.49027151],\n",
              "       [0.5107761 , 0.4892239 ],\n",
              "       [0.50073338, 0.49926662],\n",
              "       [0.51267822, 0.48732178],\n",
              "       [0.51557116, 0.48442884],\n",
              "       [0.51946112, 0.48053888],\n",
              "       [0.51230168, 0.48769832],\n",
              "       [0.51410871, 0.48589129],\n",
              "       [0.46439237, 0.53560763],\n",
              "       [0.46837088, 0.53162912],\n",
              "       [0.41905252, 0.58094748],\n",
              "       [0.46105096, 0.53894904],\n",
              "       [0.51016151, 0.48983849],\n",
              "       [0.49670101, 0.50329899],\n",
              "       [0.4923717 , 0.5076283 ],\n",
              "       [0.46171647, 0.53828353],\n",
              "       [0.48869446, 0.51130554],\n",
              "       [0.50990763, 0.49009237],\n",
              "       [0.48506357, 0.51493643],\n",
              "       [0.48746436, 0.51253564],\n",
              "       [0.51832446, 0.48167554],\n",
              "       [0.45563749, 0.54436251],\n",
              "       [0.49815943, 0.50184057],\n",
              "       [0.45074269, 0.54925731],\n",
              "       [0.50845823, 0.49154177],\n",
              "       [0.46015793, 0.53984207],\n",
              "       [0.50254118, 0.49745882],\n",
              "       [0.4675907 , 0.5324093 ],\n",
              "       [0.50137797, 0.49862203],\n",
              "       [0.46016997, 0.53983003],\n",
              "       [0.46166298, 0.53833702],\n",
              "       [0.46475064, 0.53524936],\n",
              "       [0.46797254, 0.53202746],\n",
              "       [0.50063152, 0.49936848],\n",
              "       [0.50958393, 0.49041607],\n",
              "       [0.46530326, 0.53469674],\n",
              "       [0.46128262, 0.53871738],\n",
              "       [0.45935605, 0.54064395],\n",
              "       [0.51448233, 0.48551767],\n",
              "       [0.45808966, 0.54191034],\n",
              "       [0.50264009, 0.49735991],\n",
              "       [0.4533338 , 0.5466662 ],\n",
              "       [0.4368187 , 0.5631813 ],\n",
              "       [0.50657497, 0.49342503],\n",
              "       [0.45731739, 0.54268261],\n",
              "       [0.46570994, 0.53429006],\n",
              "       [0.45425411, 0.54574589],\n",
              "       [0.50144628, 0.49855372],\n",
              "       [0.45689014, 0.54310986],\n",
              "       [0.51212871, 0.48787129],\n",
              "       [0.45858612, 0.54141388],\n",
              "       [0.468808  , 0.531192  ],\n",
              "       [0.50131739, 0.49868261],\n",
              "       [0.46546255, 0.53453745],\n",
              "       [0.50222507, 0.49777493],\n",
              "       [0.50297906, 0.49702094],\n",
              "       [0.51113976, 0.48886024],\n",
              "       [0.49626048, 0.50373952],\n",
              "       [0.48013515, 0.51986485],\n",
              "       [0.45063754, 0.54936246],\n",
              "       [0.44951954, 0.55048046],\n",
              "       [0.52596703, 0.47403297],\n",
              "       [0.42149714, 0.57850286],\n",
              "       [0.50285384, 0.49714616],\n",
              "       [0.47181115, 0.52818885],\n",
              "       [0.46232635, 0.53767365],\n",
              "       [0.50966663, 0.49033337],\n",
              "       [0.51398692, 0.48601308],\n",
              "       [0.51695589, 0.48304411],\n",
              "       [0.44887816, 0.55112184],\n",
              "       [0.4401751 , 0.5598249 ],\n",
              "       [0.50768134, 0.49231866],\n",
              "       [0.50983454, 0.49016546],\n",
              "       [0.50494073, 0.49505927],\n",
              "       [0.50356731, 0.49643269],\n",
              "       [0.46704793, 0.53295207],\n",
              "       [0.53443211, 0.46556789],\n",
              "       [0.46022118, 0.53977882],\n",
              "       [0.44044331, 0.55955669],\n",
              "       [0.45351864, 0.54648136],\n",
              "       [0.46984771, 0.53015229],\n",
              "       [0.51222111, 0.48777889],\n",
              "       [0.51231136, 0.48768864],\n",
              "       [0.50160281, 0.49839719],\n",
              "       [0.46196794, 0.53803206],\n",
              "       [0.43929472, 0.56070528],\n",
              "       [0.5082161 , 0.4917839 ]])"
            ]
          },
          "metadata": {}
        }
      ],
      "execution_count": 12,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "Step 4: Evaluating The Predection"
      ],
      "metadata": {}
    },
    {
      "cell_type": "code",
      "source": [
        "# Making the Confusion Matrix\n",
        "from sklearn.metrics import jaccard_similarity_score\n",
        "jaccard_similarity_score(y_test, yhat)"
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "execution_count": 13,
          "data": {
            "text/plain": [
              "0.5460750853242321"
            ]
          },
          "metadata": {}
        }
      ],
      "execution_count": 13,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# Confusion Matrix\n",
        "\n",
        "from sklearn.metrics import classification_report, confusion_matrix\n",
        "import itertools\n",
        "def plot_confusion_matrix(cm, classes,\n",
        "                          normalize=False,\n",
        "                          title='Confusion matrix',\n",
        "                          cmap=plt.cm.Blues):\n",
        "    \"\"\"\n",
        "    This function prints and plots the confusion matrix.\n",
        "    Normalization can be applied by setting `normalize=True`.\n",
        "    \"\"\"\n",
        "    if normalize:\n",
        "        cm = cm.astype('float') / cm.sum(axis=1)[:, np.newaxis]\n",
        "        print(\"Normalized confusion matrix\")\n",
        "    else:\n",
        "        print('Confusion matrix, without normalization')\n",
        "\n",
        "    print(cm)\n",
        "\n",
        "    plt.imshow(cm, interpolation='nearest', cmap=cmap)\n",
        "    plt.title(title)\n",
        "    plt.colorbar()\n",
        "    tick_marks = np.arange(len(classes))\n",
        "    plt.xticks(tick_marks, classes, rotation=45)\n",
        "    plt.yticks(tick_marks, classes)\n",
        "\n",
        "    fmt = '.2f' if normalize else 'd'\n",
        "    thresh = cm.max() / 2.\n",
        "    for i, j in itertools.product(range(cm.shape[0]), range(cm.shape[1])):\n",
        "        plt.text(j, i, format(cm[i, j], fmt),\n",
        "                 horizontalalignment=\"center\",\n",
        "                 color=\"white\" if cm[i, j] > thresh else \"black\")\n",
        "\n",
        "    plt.tight_layout()\n",
        "    plt.ylabel('True label')\n",
        "    plt.xlabel('Predicted label')\n",
        "print(confusion_matrix(y_test, yhat, labels=[1,0]))"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "[[74  0]\n",
            " [ 0  0]]\n"
          ]
        }
      ],
      "execution_count": 14,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# Compute confusion matrix\n",
        "cnf_matrix = confusion_matrix(y_test, yhat, labels=[1,0])\n",
        "np.set_printoptions(precision=2)\n",
        "\n",
        "\n",
        "# Plot non-normalized confusion matrix\n",
        "plt.figure()\n",
        "plot_confusion_matrix(cnf_matrix, classes=['Buy_Sell=1','Buy_Sell=0'],normalize= False,  title='Confusion matrix')"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Confusion matrix, without normalization\n",
            "[[74  0]\n",
            " [ 0  0]]\n"
          ]
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<Figure size 432x288 with 2 Axes>"
            ],
            "image/png": [
              "iVBORw0KGgoAAAANSUhEUgAAAVEAAAEmCAYAAADbUaM7AAAABHNCSVQICAgIfAhkiAAAA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75XFz4FzbbwWeA04A3m17O+A24AuSVgLOBN4L/B3wxj6q/wHFNHPbAtsB9wDHAQ+WreAvStqLYhb5nYDJwPaS3iFpe+AQ4K0USXrHOn6dS2zvWO7vXuCIim0bAe8E9gd+VP4ORwBP2d6xrP8TkjauYz/RoXLbZzTTypJ6pnr7LXAWxZRwc23/vly/MzAJ+J0kKJ6AeROwBTDH9mwAST8BjlzOPvYA/gHA9hLgKRVPyKy0V/m6o1xelSKprkbxjKPny31cXsfvtLWkb1IMGaxKMclIj4vKyUZmS3qo/B32ArapGC9do9z3/XXsKzpQkmg00wu2J1euKBPlc5WrgOttf7hXuclAs+78EPBt2//Zax9HD2Af5wAH275T0uHA7hXbetflct+ftV2ZbJG0UT/3Gx0i3fkYar8H3l7OcoSkVcrHa9wHbCxp07Lch/v4/Azgk+VnR0paneKxw6tVlLkW+HjFWOsESesANwB/L2llSatRDB3UshqwUNIKwKG9tk2RNKKMeRPgT+W+P1mWR9KbVTxLKYaptERjSNl+tGzRnS9pxXL1Cbbvl3QkcJWkxcCNwNbLqeKfgGnlXJ1LgE/avknS78pLiH5ZjotuCdxUtoSfBT5qe6akC4FZwFyKIYda/j9wc1n+bl6frP8E/C8wHjjK9ouSfkwxVjpTxc4fBQ4mhq3cOx8R0YB05yMiGpAkGhHRgCTRiIgGJIlGRDQgSTQiogFJohERDUgSjYhowP8BUjLqtffRtQwAAAAASUVORK5CYII=\n"
            ]
          },
          "metadata": {}
        }
      ],
      "execution_count": 15,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "print (classification_report(y_test, yhat))"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "             precision    recall  f1-score   support\n",
            "\n",
            "         -1       0.59      0.54      0.56       160\n",
            "          1       0.50      0.56      0.53       133\n",
            "\n",
            "avg / total       0.55      0.55      0.55       293\n",
            "\n"
          ]
        }
      ],
      "execution_count": 16,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "Accuracy is score to see how well your model is.    \n",
        "Precision is how accurate your model is and is represent the positive predictive value (PPV).    \n",
        "Recall represent the true positive rate or sensitivity. \n",
        "\n",
        "\n",
        "\n",
        "Precision is a measure of the accuracy provided that a class label has been predicted. It is defined by: precision = TP / (TP + FP)\n",
        "\n",
        "Recall is true positive rate. It is defined as: Recall =  TP / (TP + FN)\n"
      ],
      "metadata": {}
    },
    {
      "cell_type": "code",
      "source": [
        "from sklearn import metrics\n",
        "\n",
        "print(\"Accuracy:\",metrics.accuracy_score(y_test, yhat))\n",
        "print(\"Precision:\",metrics.precision_score(y_test, yhat))\n",
        "print(\"Recall:\",metrics.recall_score(y_test, yhat))"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Accuracy: 0.5460750853242321\n",
            "Precision: 0.5\n",
            "Recall: 0.556390977443609\n"
          ]
        }
      ],
      "execution_count": 22,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# Log loss( Logarithmic loss) measures the performance of a classifier where the predicted output is a probability value between 0 and 1.\n",
        "from sklearn.metrics import log_loss\n",
        "log_loss(y_test, yhat_prob)"
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "execution_count": 18,
          "data": {
            "text/plain": [
              "0.6949588373995693"
            ]
          },
          "metadata": {}
        }
      ],
      "execution_count": 18,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "LR2 = LogisticRegression(C=0.01, solver='sag').fit(X_train,y_train)\n",
        "yhat_prob2 = LR2.predict_proba(X_test)\n",
        "print (\"LogLoss: : %.2f\" % log_loss(y_test, yhat_prob2))"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "LogLoss: : 0.70\n"
          ]
        }
      ],
      "execution_count": 19,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "Receiver Operating Characteristic(ROC) curve is shows the connection/trade-off between sensitivity and specificity for every possible cut-off for a test or a combination of tests. In addition, the curve is to compare two operating characteristics  true positive rate (TPR) against the false positive rate (FPR). \n",
        "Area Under Curve (AUC) is area under the ROC curve that represent the binary classification. "
      ],
      "metadata": {}
    },
    {
      "cell_type": "code",
      "source": [
        "y_pred_proba = LR.predict_proba(X_test)[::,1]\n",
        "fpr, tpr, _ = metrics.roc_curve(y_test,  y_pred_proba)\n",
        "auc = metrics.roc_auc_score(y_test, y_pred_proba)\n",
        "plt.plot(fpr,tpr,label=\"data 1, auc=\"+str(auc))\n",
        "plt.legend(loc=4)\n",
        "plt.show()"
      ],
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<Figure size 432x288 with 1 Axes>"
            ],
            "image/png": [
              "iVBORw0KGgoAAAANSUhEUgAAAXcAAAD8CAYAAACMwORRAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvhp/UCwAAHhFJREFUeJzt3Xt0VPW5//H3I6lQEVGLtJiAQUVNiIFiMOBxiRSkQAvWwhKwFfG0jR5LqdJq/RWWWk5d9XakPS7Q4qW2VsFLK0bK0VUV0SoooaDVqC0CSpAlFzWCyCXw/P5IZjoZJplJMtc9n9daWSuz9zd7f3cmefLk2d/9/Zq7IyIiwXJYpjsgIiLJp+AuIhJACu4iIgGk4C4iEkAK7iIiAaTgLiISQAruIiIBpOAuIhJACu4iIgFUkKkT9+jRw4uLizN1ehGRnLR69ert7n5cvHYZC+7FxcXU1NRk6vQiIjnJzN5LpJ3KMiIiAaTgLiISQAruIiIBpOAuIhJACu4iIgEUN7ib2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Pco8MH9oVfeZ9JvVzSbVkDyxw033MBtt93WapvFixdTW1vbpuO+/fbbDB06lM6dO8c9frq5OzNmzODkk0+mvLycv//97zHbnXvuuZx66qkMHDiQgQMHsnXrVgBuv/12SktLKS8vZ8SIEbz33nvNvu7TTz+lsLCQ6dOnA7B7926+8Y1vcNppp9G/f3+uvfbacNu9e/cyadIkTj75ZCorK9m4cSMAO3bsYPjw4Rx55JHh44TMmjWL3r17c+SRRzbb3lK/li1bFr6GgQMH0qVLFxYvXgzAs88+y6BBgxg4cCBnn30269atA+CFF15g0KBBFBQU8NhjjzU7z89+9jPKysooKyvj4YcfDm+fNm0affv2DZ9n7dq1zb5u1apVdOrUqdnxrrnmGvr3709JSQkzZszA3QF4+OGHKS8vp3///lxzzTUx358Oc/eMfJxxxhmeDhfe9bKXXf+UX3jXy/7gyvfScs58Vltbm+kuNHP99df7rbfe2mqbSy65xB999NE2HffDDz/0V1991X/+85/HPX66/eUvf/HRo0f7wYMHfcWKFX7mmWfGbDds2DBftWrVIdufe+45/+yzz9zdff78+X7hhRc22z9jxgyfMmWK//CHP3R3988++8yfe+45d3ffu3evn3322b506VJ3d583b55fdtll7u6+cOHC8LF27drlL774ot95553h44SsWLHCP/jgA+/atWub+uXuvmPHDj/mmGPC7fr16xf+mZw3b55fcskl7u6+YcMGf+211/ziiy9u9t4vWbLER44c6fv37/ddu3b5GWec4fX19e7e+s9JQ0ODDx8+3MeMGRNu89JLL/lZZ53lDQ0N3tDQ4EOGDPFly5b59u3bvXfv3r5161Z3d586dao/88wzMY8b6/cJqPEEYmxgM/fIjD1Ua9fwx/xw4403cuqppzJy5Ejeeeed8Pa7776bwYMHM2DAACZMmMDu3bt5+eWXqa6u5uqrr2bgwIG8++67MdtF69mzJ4MHD27TSIY5c+YwePBgysrKqKqqCmdx5557LjU1NQBs376d4uJiAA4cOMBPf/pTTj/9dMrLy7njjjsSOs8TTzzB1KlTMTOGDBnCJ598wpYtWxLu5/DhwzniiCMAGDJkCHV1deF9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Vx55ZXcfPPNdOrUqdmx1q1bx1tvvRX+D+O8887jhRde4JxzzuHOO+9k0qRJHHbYYZx11lmsX7++Q9+TWHIuuLe2WDVoweps0lqGnUotBY9p06axePFiBgwYwP3338/zzz/foXZtsWfPHq644gpqamro3bs3N9xwQ/hBr4KCAg4ePBhuF+LuMa8lXuZeVFTEpk2bwtvr6urC5YhIhYWN/9F269aNiy66iFdffTUc3J955hluvPFGli9fTufOnQFYsWIFL774IvPnz2fXrl3s27ePI488kptuugmAqqoq+vXrx5VXXhk+R6gvRUVFNDQ0UF9fH/4j1R6x+hXyyCOPcMEFF4RLZdu2beO1116jsrISgEmTJjF69Oi455g1axazZs0C4KKLLqJfv34A4f98OnfuzKWXXhq+kV5TU8PkyZOBxrLa0qVLKSgo4F//+hdDhgwJ3xgeM2YMK1eu5JxzzmHcuHHhP+wLFiw45A9DMuRczT16QY1oekgpv51zzjk8/vjjfP755+zcuZMnn3wyvG/nzp306tWL/fv38+CDD4a3d+vWjZ07d8Ztl6gRI0aweXPzBCQUtHv06MGuXbuajagoLi5m9erVAM22jxo1irvuuouGhgaAcFlm7ty5rF279pCP0CiV8ePH84c//AF3Z+XKlXTv3v2QkkxDQwPbt28HGp8qXrJkCWVlZQCsWbOGyy67jOrq6mY15AcffJD333+fjRs3cttttzF16tRwYJ89ezb19fX8+te/bnae8ePH8/vf/z58bV/72tfanbm31K+QhQsXMmXKlPDrY445hvr6ev75z38C8Ne//pWSkpJWz3HgwAF27NgBwOuvv87rr78evr8Qum/h7ixevDj8/dqwYQMbN25k48aNTJw4kfnz5/Otb32LPn36sHz5choaGti/fz/Lly8Pnz80Munjjz9m/vz5fP/732/X96RVidx1BUYD7wDrgGtj7O8MPNy0/xWgON4x2zta5sK7XvYL73q5XV8rqZcNo2V++ctf+imnnOLnnXeeX3rppeHRLPPnz/fi4mIfNmyYT58+PTxy4m9/+5uXlJT4wIEDfd26dS22i7RlyxYvLCz0bt26effu3b2wsNDr6+v9wIED3qdPH9+9e/chXz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uIhJACu4iIgGk4C4iEkAK7iIiAfT/Ab3NRKNZllCQAAAAAElFTkSuQmCC\n"
            ]
          },
          "metadata": {}
        }
      ],
      "execution_count": 25,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    }
  ],
  "metadata": {
    "kernel_info": {
      "name": "python3"
    },
    "language_info": {
      "file_extension": ".py",
      "nbconvert_exporter": "python",
      "mimetype": "text/x-python",
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "name": "python",
      "version": "3.5.5",
      "pygments_lexer": "ipython3"
    },
    "kernelspec": {
      "name": "python3",
      "language": "python",
      "display_name": "Python 3"
    },
    "nteract": {
      "version": "0.23.1"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 4
}